#include "CPrince.h"


CPrince::CPrince(IrrlichtDevice* device)
{
	ISceneManager* smgr = device->getSceneManager();
	IVideoDriver* driver = device->getVideoDriver();

	mesh.push_back(smgr->getMesh(L"data/prince/prince_idle_pose.b3d"));
	mesh.push_back(smgr->getMesh(L"data/prince/prince_1hand_combo_01.b3d"));
	mesh.push_back(smgr->getMesh(L"data/prince/prince_1hand_combo_02.b3d"));
	mesh.push_back(smgr->getMesh(L"data/prince/prince_1hand_combo_03.b3d"));

	node = smgr->addAnimatedMeshSceneNode(mesh[0]);

	node->setAnimationSpeed(10);
	node->setLoopMode(false);
	
	node->setMaterialFlag(EMF_LIGHTING, false);
}


CPrince::~CPrince(void)
{
}


void CPrince::OnAnimationEnd(scene::IAnimatedMeshSceneNode* node)
{
	idlePose();
}


void CPrince::idlePose(void)
{
	node->setMesh(mesh[IDLE]);
	node->setMaterialFlag(EMF_LIGHTING, false);
	
	// Disable callback interface
	node->setAnimationEndCallback(NULL);
}


void CPrince::doCombo(void)
{
	u32 rand = genRandomInt(0, 9);

	if (rand < 4)							// 40%
	{
		node->setMesh(mesh[COMBO_01]);
	}
	else if (rand < 7)						// 30%
	{
		node->setMesh(mesh[COMBO_02]);
	}
	else									// 30%
	{
		node->setMesh(mesh[COMBO_03]);
	}
		
	node->setMaterialFlag(EMF_LIGHTING, false);

	// Enable callback interface
	node->setAnimationEndCallback(this);
}


IAnimatedMeshSceneNode* CPrince::getNode(void)
{
	return node;
}


vector3df CPrince::getPosition(void)
{
	return node->getPosition();
}


void CPrince::setPosition(vector3df& position)
{
	this->position = position;

	node->setPosition(position);
	node->updateAbsolutePosition();
}